<?PHP
require_once( 'facepp_sdk.php');
########################
###     example      ###
########################
$facepp = new Facepp();

#detect local image 
/*
$params=array('img'=>'http://www.faceplusplus.com.cn/wp-content/themes/faceplusplus/assets/img/demo/2.jpg');
$params['attribute'] = 'gender,age,race,smiling,glass,pose';
$response = $facepp->execute('/detection/detect',$params);
print_r($response);
*/
$picUrl = 'http://mmbiz.qpic.cn/mmbiz/sJfr4JaKW5YIDOEFIWhc6ibskQcArsXLq9Cg2ibs8qMcFt7tJrHPmlJDiczvNLibQxiahFuXXnXdH7kAWR5rK5qPbzA/0';
#detect image by url
$params=array('url'=>'http://mmbiz.qpic.cn/mmbiz/sJfr4JaKW5YIDOEFIWhc6ibskQcArsXLq9Cg2ibs8qMcFt7tJrHPmlJDiczvNLibQxiahFuXXnXdH7kAWR5rK5qPbzA/0');
//$params['attribute'] = 'gender,age,race,smiling,glass,pose';
$response = $facepp->execute('/detection/detect',$params);
print_r($response['http_code'] );

if( $response['http_code'] == 200){
    #json decode 
    $data = json_decode($response['body'],1);
    #get face detect
    //print_r($data);
    foreach ($data['face'] as $face) {
        //$response = $facepp->execute('/detection/landmark',array('face_id'=>$face['face_id']));
        //$attr = array('attribute'=>$face['attribute']);
        $attr = $face['attribute'];
        $back =$attr['age']['value'];//.',性别:'. attr['gender']->value.',种族:'.attr['race']->value.',微笑程度:'.attr['smiling']->value.'眼镜佩戴分析结果:'.attr['glass']->value.',脸部姿势分析:'attr['pose']->value;
        var_dump($back);
        var_dump('<br/>');
        print_r($back);
    }
    /*
    #create person 
    $response = $facepp->execute('/person/create',array('person_name'=>'unique_person_name'));
    print_r($response);

    #delete person
    $response = $facepp->execute('/person/delete',array('person_name'=>'unique_person_name'));
    print_r($response);
*/
}
else
{
    var_dump("####<br/>");
    var_dump($response);
}   